package com.atguigu.gulimall.order.vo;

import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

public class OrderConfirmVo {

    //收货地址列表
    @Setter @Getter
    List<MemberAddressVo> address;

    //所有选中的购物项
    @Setter @Getter
    List<OrderItemVo> items;

    //发票...

    //优惠卷
    @Setter @Getter
    Integer integration;

    //防重令牌
    @Setter @Getter
    String orderToken;

    @Setter @Getter
    Map<Long,Boolean> stocks;

    //订单总额
    //BigDecimal total;
    public BigDecimal getTotal(){
        BigDecimal sum = new BigDecimal("0");
        if(items != null){
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }
    //应付价格
    BigDecimal payPrice;
    public BigDecimal getPayPrice() {
        BigDecimal paysum = new BigDecimal("0");
        if(items != null){
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount()));
                paysum = paysum.add(multiply);
            }
        }
        //TODO 需要减掉优惠
        return paysum;

    }

    public Integer getCount(){
        Integer count = 0;
        if(items != null){
            for (OrderItemVo item : items) {
                count += item.getCount();
            }
        }
        return count;
    }
}
